/**
 * <copyright>
 *
 * Copyright (c) 2015 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 *
 * </copyright>
 *
 * $Id$
 */
package org.eclipse.jet.internal.taglib;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jet.taglib.CustomTag;
import org.eclipse.jet.taglib.TagInstanceFactory;
import org.eclipse.jet.taglib.TagLibrary;

public class TagFactoryManager
{

  private static org.eclipse.jet.internal.taglib.control.TagFactory controlLibary;
  private static org.eclipse.jet.internal.taglib.custom.TagFactory customLibary;
  private static org.eclipse.jet.internal.taglib.extend.TagFactory extendLibary;
  private static org.eclipse.jet.internal.taglib.format.TagFactory formatLibary;
  private static org.eclipse.jet.internal.taglib.java.TagFactory javaLibary;
  private static org.eclipse.jet.internal.taglib.merge.TagFactory mergeLibary;
  private static org.eclipse.jet.internal.taglib.common.TagFactory commonLibary;
  private static org.eclipse.jet.internal.taglib.task.TagFactory taskLibary; 
  private static org.eclipse.jet.internal.taglib.workspace.TagFactory workspaceLibary;
  private static org.eclipse.jet.internal.taglib.xml.TagFactory xmlLibary;
  private static org.eclipse.jet.internal.taglib.formatExt.TagFactory formatExtLibary;
  
  private static List<TagInstanceFactory> tagLibaries = new ArrayList<TagInstanceFactory>();
  
  static{
    controlLibary = new org.eclipse.jet.internal.taglib.control.TagFactory();
    customLibary = new org.eclipse.jet.internal.taglib.custom.TagFactory();
    extendLibary = new org.eclipse.jet.internal.taglib.extend.TagFactory();
    formatLibary = new org.eclipse.jet.internal.taglib.format.TagFactory();
    javaLibary = new org.eclipse.jet.internal.taglib.java.TagFactory();
    mergeLibary = new org.eclipse.jet.internal.taglib.merge.TagFactory();
    commonLibary = new org.eclipse.jet.internal.taglib.common.TagFactory();
    taskLibary = new org.eclipse.jet.internal.taglib.task.TagFactory(); 
    workspaceLibary = new org.eclipse.jet.internal.taglib.workspace.TagFactory();
    xmlLibary = new org.eclipse.jet.internal.taglib.xml.TagFactory();
    formatExtLibary = new org.eclipse.jet.internal.taglib.formatExt.TagFactory();
    tagLibaries.add(controlLibary);
    tagLibaries.add(customLibary);
    tagLibaries.add(extendLibary);
    tagLibaries.add(formatLibary);
    tagLibaries.add(javaLibary);
    tagLibaries.add(mergeLibary);
    tagLibaries.add(commonLibary);
    tagLibaries.add(taskLibary);
    tagLibaries.add(workspaceLibary);
    tagLibaries.add(xmlLibary);
    tagLibaries.add(formatExtLibary);
  }
  
  private TagFactoryManager()
  {
  }
  public static CustomTag findTag(TagLibrary library, String tagName){
    String libraryId = library.getLibraryId();
    if(libraryId == null){
      return null;
    }
    for (int i = 0; i < tagLibaries.size(); i++)
    {
      TagInstanceFactory factory = tagLibaries.get(i);
      if(libraryId.equals(factory.libraryId())){
        CustomTag customTag = factory.createCustomTag(tagName);
        return customTag;
      }
    }
    return null;
  }

}
